package com.situ.personal.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/ajax")
public class AjaxServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		/**
		 * 1.拿到jsp传来的数据
		 * *以下回传数据  与上边没关系
		 * 2.resp回传 utf-8数据
		 * 3.回传数据（data） name设置成了什么    age设置成了什么
		 */
		// 1.获取jsp数据
		System.out.println("AjaxServlet.doGet()");
		String name = req.getParameter("name");
		System.out.println("name"+name);
		
		//2.回传utf-8
		resp.setContentType("text/html;charset=utf-8");
		resp.getWriter().write("{\"name\":\"张三\",\"age\":888}");
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("AjaxServlet.doPost()");
		String name = req.getParameter("name");
		System.out.println("name"+name);
		
		resp.setContentType("text/html;charset=utf-8");
		resp.getWriter().write("{\"name\":\"李四\",\"age\":149}");
	}
}
